;+
; NAME:
;       CREATE_VELOCITY_STRUCTURE
;
; PURPOSE:
;       Creates the velocity structure for holding spectra of all
;       dense gas tracer velocities, plus GRS 13CO, based on the
;       current parameters in galactic_params.pro.  Places strucutre
;       into an IDL save file.
;
; CATEGORY:
;       distance-omnibus utility
;
; CALLING SEQUENCE:
;       CREATE_VELOCITY_STRUCTURE
;
; INPUTS:
;       NONE
;
; OPTIONAL INPUTS:
;       NONE
;
; KEYWORD PARAMETERS:
;       NONE
;
; OUTPUTS:
;       Creates an array of structures 'VELOCITY', and saves it as an
;       IDL save file: ./local/bgps_velocity_struct.sav
;
; OPTIONAL OUTPUTS:
;       NONE
;
; MODIFICATION HISTORY:
;
;       Created:  09/13/10, TPEB -- Initial Version
;       Modified: 04/27/11, TPEB -- Code cleanup and added documentation
;       Modified: 07/14/11, TPEB -- Cleaned up the memory hog by
;                                   undefining the big variables at
;                                   the end of the routine.  Also
;                                   moved the GRS 13CO import from
;                                   here to the routine
;                                   import_densegas_spectra.pro.
;       Modified: 08/29/11, TPEB -- Added 2 new velocity structure
;                                   elements: dense gas S/N and dense
;                                   gas VLSR fit.
;       Modified: 10/17/11, TPEB -- Added structure elements for the
;                                   filename(s) from which the spectra
;                                   were taken.  Used for
;                                   backwards-checking.
;       Modified: 11/08/11, TPEB -- Removing use of the CSO CS(5-4)
;                                   sprectra from use in the
;                                   repository.
;       Modified: 11/30/11, TPEB -- Added (l,b) to this structure, for
;                                   ease of use in other analyses.
;
;-

PRO CREATE_VELOCITY_STRUCTURE
  
  COMPILE_OPT OBSOLETE
  
  ;; Get current parameters
  defsysv, '!MW', exists = exists
  IF NOT exists THEN galactic_params 
  
  ;; Read in BGPS Distance Database
  s = read_bgps_csv(CSV=csv,/ver)
  
  ;; Create Structure
  velocity = REPLICATE( $
             CREATE_STRUCT('cnum',0L,'l',0.,'b',0.,'has_rv_types',0L,$
                           'v_std',findgen(!MW.NVBINS)*!MW.DELTAV + !MW.VSTART,$
                           'hcop',fltarr(!MW.NVBINS),'n2hp',fltarr(!MW.NVBINS),$
                           'cs21',fltarr(!MW.NVBINS),'nh3',fltarr(!MW.NVBINS),$
                           'densegas',fltarr(!MW.NVBINS),$
                           'grs13co',fltarr(!MW.NVBINS),$
                           'n_hcop',0b,'n_n2hp',0b,'n_nh3',0b,'n_cs21',0b,$
                           'hcop_fn','','n2hp_fn','','cs21_fn','',$
                           'p_hisa',0.d,'sig_hcop',0.d,'sig_n2hp',0.d,$
                           'sig_cs21',0.d,'sig_nh3',0.d,'vlsr',0.d), $
             csv.nrows)
  
  ;; Import structure elements from other structures
  velocity.cnum = s.cnum
  velocity.l    = s.glon_peak
  velocity.b    = s.glat_peak
  
  save,velocity,filename='./local/bgps_velocity_struct.sav',/ver
  
  ;; Clean up the memory, dude
  undefine,velocity
  
END
